import {UserActions} from './user';

const initialState = {};

export const orderActions = {
  CREATE_ORDER: 'create_order',
  CREATE_ORDER_PRODUCT_ADD: 'create_order_product_add',
  CREATE_ORDER_PRODUCT_UPDATE: 'create_order_product_update',
};

export function createOrder(payload) {
  return {
    type: orderActions.CREATE_ORDER,
    payload,
  };
}

export function createOrderProductAdd(payload) {
  return {
    type: orderActions.CREATE_ORDER_PRODUCT_ADD,
    payload,
  };
}

export function createOrderProductUpdate(payload) {
  return {
    type: orderActions.CREATE_ORDER_PRODUCT_UPDATE,
    payload,
  };
}

export default function orderState(state = initialState, action) {
  switch (action.type) {
    case orderActions.CREATE_ORDER:
      return {...state, ...action.payload};
    case orderActions.CREATE_ORDER_PRODUCT_ADD:
      return {...state, ...action.payload};
    case orderActions.CREATE_ORDER_PRODUCT_UPDATE:
      return {...state, ...action.payload};
    case UserActions.USER_SIGN_OUT:
      return {};
    default:
      return state;
  }
}
